package com.app.android.coliy.ui.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;

import com.app.android.coliy.R;
import com.app.android.coliy.bean.ElementsInfo;
import com.app.android.coliy.util.BitmapUtil;

public class ElementView_Img extends ElementView_Base {

    public ElementView_Img(Context context, ElementsInfo info) {
        super(context, info);
        init();
    }

    @Override
    public void refreshUI() {
        super.refreshUI();
        iv_img.setImageBitmap(bitmap);
        setRotation(elementsInfo.orientation);
    }

    ImageView iv_img;
    Bitmap bitmap;

    private void init() {
        View.inflate(mContext, R.layout.view_ele_img, this);
        iv_img = findViewById(R.id.iv_img);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    bitmap = BitmapUtil.getSmallBitmap(elementsInfo.imgLocalPath);
                    ((Activity) getContext()).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            refreshUI();
                        }
                    });
                } catch (Exception E) {

                }
            }
        }).start();
    }
}
